# -*- coding: utf-8 -*-
# @Time : 2022-06-16 16:09
# @Author : Z
# @Function : 报表数据查询
from Keywords.inter_keys import Inter

inter = Inter()

# 登陆
inter.post_data('http://api.bywrc.com:9091/loginNew', '{"username":"maozuoyuan","password":"Abc&123"}')
# 断言登陆成功
inter.assert_equals("$.msg","成功")
# 提取token，userId
inter.save_json("$.data.token", 'newtoken')
inter.save_json("$.data.userId", 'newid')
# token添加都请求头
inter.add_header('token', '{newtoken}')
# 添加userID到头
inter.add_header('userId', '{newid}')
# 查询
inter.get(
    'http://api.bywrc.com:9091/admin/pc/report/summary-device-income-group-by-device?pageNum=1&pageSize=10&customerId=175221000000515319&storeId=&customerFlag=1&beginDate=2022-06-15&endDate=2022-06-15&userId={newid}')
# 提取金额
inter.save_json('$.data[0].factAmount', 'newfactAmount')
# 断言接口返回的结果和数据库返回的结果一致
inter.assertmysql(
    "select d.customer_name as '客户',d.customer_flag as '模式(1:合营 0:其他)',d.store_name as '门店',d.name as '设备',t.device_serial_number as '设备编号',sum(t.income_amount) as '营业额',sum(t.refund_amount) as '退款金额',sum(t.fact_amount) as '实收金额',sum(t.order_count) as '订单数',sum(t.product_quantity) as '菜品数量' from dc_device_income t inner join dc_device d on t.device_serial_number=d.serial_number where d.customer_name='广州卓思道酒店管理有限公司从化分公司' and t.income_date >= '2022-06-15' and t.income_date <= '2022-06-15' GROUP BY d.customer_name,d.customer_flag,d.store_name,d.name,t.device_serial_number;","营业额","{newfactAmount}")
inter.get('http://api.bywrc.com:9091/logoutNew')
# 断言登出成功
inter.assert_equals("$.msg","成功")
